package cn.caplike.demo.repository.java;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.ImmutableMap;
import lombok.extern.slf4j.Slf4j;

/**
 * @author LiKe
 * @version 1.0.0
 * @date 2020-08-25 15:11
 */
@Slf4j
public class HashTester {

    public static void main(String[] args) {

//        long value = 4048637L;
//        long target = value << 2;
//        System.out.println(target);
//
//        final String subject = "Sth like that.";
//        final int hashCode = subject.hashCode();
//        System.out.println("hashCode: " + hashCode % 5);

        //final int size = new HashSet<>(Arrays.asList(new User("cap"), new User("lok"), new User("som"))).size();
        //System.out.println(new User("cap"));
        //System.out.println(new User("lok"));
        //System.out.println(new User("som"));

        System.out.println(new User(("like")).hashCode());
        System.out.println(new User(("like")).hashCode());

        System.out.println(JSON.parseObject(JSON.toJSONString(ImmutableMap.of("name", "like", "sex", "male", "level", 99, "serial", "100-23-32-A-C"))).hashCode());
        System.out.println(JSON.parseObject(JSON.toJSONString(ImmutableMap.of("name", "like", "sex", "male", "level", 99, "serial", "100-23-32-A-C"))).hashCode());
    }
}

class User {
    private final String name;

    public User(String name) {
        this.name = name;
    }

    @Override
    public int hashCode() {
        return name.length();
    }

    @Override
    public boolean equals(Object o) {
        return this.hashCode() == o.hashCode();
    }
}
